const {
    vital,
    success,
    error,
    info,
    getPrint,
    warn,
    log,
} = require("../utils/log_tool");
const { toArray } = require("../utils/transform_tool");
const { BaseCommand } = require("./base");

class ValidRequiredCommand extends BaseCommand {
    async execute() {
        const data = this.selfData;
        const keys = toArray(data.key);
        let failed = false;
        log("");
        for (let index = 0; index < keys.length; index++) {
            const key = keys[index];
            const ret = this.getDataByKey(key);
            if (ret == null) {
                failed = true;
                warn(`${key} => ${getPrint(ret)}`);
            } else {
                info(`${key} => ${getPrint(ret)}`);
            }
        }
        if (failed) {
            throw `参数校验失败,请检查环境变量或者启动参数`;
        } else {
            success(`参数校验成功`);
        }
    }
}

module.exports = {
    ValidRequiredCommand,
};
